<template>
  <div class="user-info">
    <el-dropdown trigger="click">
      <span class="el-dropdown-link">
        <el-avatar
          size="small"
          src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
        />
        <span>{{ userName }}, 你好</span>
        <el-icon class="el-icon--right">
          <!-- <arrow-down /> -->
          <i class="el-icon-arrow-down el-icon--right" />
        </el-icon>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item>
            <div class="drop-item">
              用户信息
              <el-icon>
                <avatar />
              </el-icon>
            </div>
          </el-dropdown-item>

          <el-dropdown-item>
            <div class="drop-item">
              系统管理
              <el-icon>
                <tools />
              </el-icon>
            </div>
          </el-dropdown-item>

          <el-dropdown-item @click="outLogin" divided>
            <div class="drop-item">
              退出登录
              <el-icon>
                <close-bold />
              </el-icon>
            </div>
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
import { Avatar, CloseBold, Tools } from '@element-plus/icons';
import { defineComponent, computed } from 'vue';
import { useStore } from '@/store';
import { localCache } from '@/utils';
import { useRouter } from 'vue-router';

export default defineComponent({
  setup() {
    const store = useStore();
    const userName = computed(() => store.state.login.userInfo?.name);
    const router = useRouter();
    const outLogin = function () {
      localCache.deleteCache('token');
      router.push({ path: '/' });
    };

    return {
      userName,
      outLogin,
    };
  },

  components: {
    Avatar,
    CloseBold,
    Tools,
  },
});
</script>

<style lang="less" scoped>
.drop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 88px;
}
.user-info {
  .el-dropdown-link {
    display: flex;
    align-items: center;
    cursor: pointer;
  }
}
</style>
